﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lapas.Common.Forms;
using Lapas.Common;
using WorkDAL;
using WorkDAL.BranchCode;
using Common;

namespace BranchCode
{
    public partial class BranchCodeListForm : ListForm
    {
        public BranchCodeListForm()
        {
            InitializeComponent();
        }

        protected override DataGridView Grid
        {
            get
            {
                return this.MainGrid;
            }
        }

        protected override void FormatGrid()
        {
            UIFormat.FormatGrid(MainGrid, false, true, true, false);
            UIFormat.SetGridColumnFormat(ColBranchCode, FormatType.NormalText);
            UIFormat.SetGridColumnFormat(ColNameViet, FormatType.NormalText);
            UIFormat.SetGridColumnFormat(ColAddressViet, FormatType.NormalText);
            UIFormat.SetGridColumnFormat(ColTaxCode, FormatType.NormalText);
            UIFormat.SetGridColumnFormat(ColPhoneNumber, FormatType.NormalText);
        }

        private void GetData()
        {
            try
            {
                List<tbBranchCode> branchCodeList = new List<tbBranchCode>();
                if (CommonSettings.isSuperAdmin)
                    branchCodeList = BranchCodeDataAccess.Instance().BranchCodeGetList();
                else
                    branchCodeList = BranchCodeDataAccess.Instance().BranchCodeGetList(CommonSettings.UserBranchCode);

                bindingSource.DataSource = branchCodeList;
                MainGrid.DataSource = bindingSource;
                BindData();
            }
            catch (Exception ex)
            {
                DisplayMessage.ShowError(ex.Message);
                return;
            }
        }

        protected override void BindData()
        {
            base.BindData();
        }

        private void BranchCodeListForm_Load(object sender, EventArgs e)
        {
            if (CommonSettings.isSuperAdmin)
            {
                mainToolStrip.Enabled = true;
            }
            else
            {
                mainToolStrip.Enabled = false;
            }

            GetData();
        }


        protected override void DisplayEditForm(EditForm.EditFormAction action)
        {
            BranchCodeEditForm branchCodeEditForm = new BranchCodeEditForm();
            branchCodeEditForm.FormAction = action;

            if (action == EditForm.EditFormAction.Change)
            {
                branchCodeEditForm.branchCode = (tbBranchCode)bindingSource.Current;
            }

            branchCodeEditForm.ShowDialog();
            if (branchCodeEditForm.Reload)
            {
                GetData();
            }
        }

    }
}
